package com.education.wisdom.controller;

import java.util.List;

import com.education.common.utils.ApiReturnObject;
import com.education.wisdom.pojo.JrMedal;
import com.education.wisdom.service.IJrMedalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
/**
 * 勋章规则 信息操作处理
 *
 * @author d
 * @date 2021-08-18
 */
@RestController
@RequestMapping("/jrMedal")
public class JrMedalController{

    @Autowired
    private IJrMedalService jrMedalService;

    /**
     * 查询勋章规则列表
     */
    @GetMapping("/list")
    public ApiReturnObject list(JrMedal jrMedal) {
        List<JrMedal> list = jrMedalService.selectJrMedalList(jrMedal);
        if(list.size() > 0){
            return new ApiReturnObject("200","查询成功",list.get(0));
        }else {
            return new ApiReturnObject("200","查询成功",new JrMedal());
        }
    }


    /**
     * 新增保存勋章规则
     */
    @PostMapping("/add")
    public ApiReturnObject addSave(@RequestBody JrMedal jrMedal) {
        jrMedalService.insertJrMedal(jrMedal);
        return new ApiReturnObject("200","添加成功","");
    }


    /**
    * 详情勋章规则
    */
    @GetMapping("/selectOne")
    public ApiReturnObject selectOne(Integer id){
        JrMedal result = jrMedalService.selectJrMedalById(id);
        return new ApiReturnObject("200","查询成功",result);
    }

    /**
     * 修改保存勋章规则
     */
    @PostMapping("/update")
    public ApiReturnObject editSave(@RequestBody JrMedal jrMedal) {
        jrMedalService.updateJrMedal(jrMedal);
        return new ApiReturnObject("200","修改成功","");
    }

    /**
     * 删除勋章规则
     */
    @PostMapping("/del")
    public ApiReturnObject remove(String ids) {
        jrMedalService.deleteJrMedalByIds(ids);
        return new ApiReturnObject("200","删除成功","");
    }
}